<!DOCTYPE html>
<!--

// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

-->
<html>
<head>
<title></title>
<script src="../../third_party/closure-library/closure/goog/base.js"></script>
<script>
goog.require('goog.testing.jsunit');
</script>
<script src="../../src/traceur.js"></script>
<script src="ArrowFunctions/ArrowFunctions.js" type="text/traceur"></script>
<script src="ArrowFunctions/Error_Disabled.js" type="text/traceur"></script>
<script src="ArrowFunctions/Error_FreeVariableChecker.js" type="text/traceur"></script>
<script src="ArrowFunctions/Error_InvalidFormalParameters.js" type="text/traceur"></script>
<script src="ArrowFunctions/Error_SpreadNotLast.js" type="text/traceur"></script>
<script src="ArrowFunctions/Error_SpreadOutsideFormals.js" type="text/traceur"></script>
<script src="ArrowFunctions/FreeVariableChecker.js" type="text/traceur"></script>
<script src="ArrowFunctions/Skip_Frozen.js" type="text/traceur"></script>
<script src="ArrowFunctions/Skip_InitialiserShorthand.js" type="text/traceur"></script>
<script src="ArrowFunctions/Skip_SoftBind.js" type="text/traceur"></script>
<script src="ArrowFunctions/ThisBindings.js" type="text/traceur"></script>
<script src="Await/Complete.js" type="text/traceur"></script>
<script src="Await/Error_Disabled.js" type="text/traceur"></script>
<script src="Await/Finally.js" type="text/traceur"></script>
<script src="Await/Throw.js" type="text/traceur"></script>
<script src="Await/Timeout.js" type="text/traceur"></script>
<script src="Await/Value.js" type="text/traceur"></script>
<script src="Await/Yield.js" type="text/traceur"></script>
<script src="Cascade/Arguments.js" type="text/traceur"></script>
<script src="Cascade/Error_Disabled.js" type="text/traceur"></script>
<script src="Cascade/Error_Literal.js" type="text/traceur"></script>
<script src="Cascade/This.js" type="text/traceur"></script>
<script src="Cascade/Simple.js" type="text/traceur"></script>
<script src="Classes/ClassMethodInheritance.js" type="text/traceur"></script>
<script src="Classes/Constructor.js" type="text/traceur"></script>
<script src="Classes/ConstructorChaining.js" type="text/traceur"></script>
<script src="Classes/ConstructorMember.js" type="text/traceur"></script>
<script src="Classes/DeriveFromObject.js" type="text/traceur"></script>
<script src="Classes/Skip_DerivedButton.js" type="text/traceur"></script>
<script src="Classes/EmptyClass.js" type="text/traceur"></script>
<script src="Classes/Error_Disabled.js" type="text/traceur"></script>
<script src="Classes/ExtendNull.js" type="text/traceur"></script>
<script src="Classes/ExtendObject.js" type="text/traceur"></script>
<script src="Classes/FieldInheritance.js" type="text/traceur"></script>
<script src="Classes/FieldInitializers.js" type="text/traceur"></script>
<script src="Classes/FieldLookup.js" type="text/traceur"></script>
<script src="Classes/Fields.js" type="text/traceur"></script>
<script src="Classes/Getters.js" type="text/traceur"></script>
<script src="Classes/Skip_HTMLBlockquoteElement.js" type="text/traceur"></script>
<script src="Classes/Inheritance.js" type="text/traceur"></script>
<script src="Classes/InheritanceFromMemberExpression.js" type="text/traceur"></script>
<script src="Classes/InheritanceFromNonclass.js" type="text/traceur"></script>
<script src="Classes/InheritanceNameBinding.js" type="text/traceur"></script>
<script src="Classes/Method.js" type="text/traceur"></script>
<script src="Classes/MethodInheritance.js" type="text/traceur"></script>
<script src="Classes/MethodLookup.js" type="text/traceur"></script>
<script src="Classes/NameBinding.js" type="text/traceur"></script>
<script src="Classes/OptionalParams.js" type="text/traceur"></script>
<script src="Classes/PropertyAccessors.js" type="text/traceur"></script>
<script src="Classes/RestParams.js" type="text/traceur"></script>
<script src="Classes/SimpleSuper.js" type="text/traceur"></script>
<script src="Classes/SuperChaining.js" type="text/traceur"></script>
<script src="Classes/SuperMissing.js" type="text/traceur"></script>
<script src="Classes/SuperSet.js" type="text/traceur"></script>
<script src="Collection/ArrayLike.js" type="text/traceur"></script>
<script src="Collection/Call.js" type="text/traceur"></script>
<script src="Collection/Simple.js" type="text/traceur"></script>
<script src="DefaultParameters/Error_SetAccessor.js" type="text/traceur"></script>
<script src="DefaultParameters/Simple.js" type="text/traceur"></script>
<script src="Destructuring/Arguments.js" type="text/traceur"></script>
<script src="Destructuring/Array.js" type="text/traceur"></script>
<script src="Destructuring/Class.js" type="text/traceur"></script>
<script src="Destructuring/DefaultParams.js" type="text/traceur"></script>
<script src="Destructuring/Error_Disabled.js" type="text/traceur"></script>
<script src="Destructuring/Error_ForInWithInitializer.js" type="text/traceur"></script>
<script src="Destructuring/Error_ForOfWithInitializer.js" type="text/traceur"></script>
<script src="Destructuring/EvaluatesToRvalue.js" type="text/traceur"></script>
<script src="Destructuring/EvaluationOrder.js" type="text/traceur"></script>
<script src="Destructuring/ForInLoop.js" type="text/traceur"></script>
<script src="Destructuring/ForOfLoop.js" type="text/traceur"></script>
<script src="Destructuring/FunctionArrayPattern.js" type="text/traceur"></script>
<script src="Destructuring/FunctionObjectPattern.js" type="text/traceur"></script>
<script src="Destructuring/Method.js" type="text/traceur"></script>
<script src="Destructuring/NestedScopeArguments.js" type="text/traceur"></script>
<script src="Destructuring/Object.js" type="text/traceur"></script>
<script src="Destructuring/PatternInRestPosition.js" type="text/traceur"></script>
<script src="Destructuring/Rest.js" type="text/traceur"></script>
<script src="Destructuring/ScopeThis.js" type="text/traceur"></script>
<script src="Destructuring/SetAccessor.js" type="text/traceur"></script>
<script src="Destructuring/TopLevel.js" type="text/traceur"></script>
<script src="Destructuring/VarDecl.js" type="text/traceur"></script>
<script src="Error_FunctionParam.js" type="text/traceur"></script>
<script src="IsExpression/Error_Disabled.js" type="text/traceur"></script>
<script src="IsExpression/Error_Syntax.js" type="text/traceur"></script>
<script src="IsExpression/ObjectIs.js" type="text/traceur"></script>
<script src="IsExpression/Simple.js" type="text/traceur"></script>
<script src="IsExpression/Syntax.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidExport.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidExport2.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidExport3.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidModuleDeclaration.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidModuleDeclaration2.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidModuleDeclaration3.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidModuleDeclaration4.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidModuleDeclaration5.js" type="text/traceur"></script>
<script src="Modules/Error_InvalidModuleDeclaration6.js" type="text/traceur"></script>
<script src="Modules/Error_MissingExport.js" type="text/traceur"></script>
<script src="Modules/Exports.js" type="text/traceur"></script>
<script src="Modules/ImportFromLocalModule.js" type="text/traceur"></script>
<script src="Modules/ImportFromLocalModuleStar.js" type="text/traceur"></script>
<script src="Modules/ImportFromStandardLibrary.js" type="text/traceur"></script>
<script src="Modules/ImportFromStandardLibraryStar.js" type="text/traceur"></script>
<script src="ObjectInitialiserShorthand/Error_Disabled.js" type="text/traceur"></script>
<script src="ObjectInitialiserShorthand/Error_Keyword.js" type="text/traceur"></script>
<script src="ObjectInitialiserShorthand/Error_MissingVar.js" type="text/traceur"></script>
<script src="ObjectInitialiserShorthand/Ok.js" type="text/traceur"></script>
<script src="PrivateNames/Inherited.js" type="text/traceur"></script>
<script src="PrivateNames/Name.js" type="text/traceur"></script>
<script src="PrivateNames/Object.js" type="text/traceur"></script>
<script src="PropertyMethodAssignment/PropertyMethodAssignment.js" type="text/traceur"></script>
<script src="PropertyMethodAssignment/Error_Disabled.js" type="text/traceur"></script>
<script src="PropertyMethodAssignment/Error_NotNamed.js" type="text/traceur"></script>
<script src="PropertyOptionalComma/Error_Disabled.js" type="text/traceur"></script>
<script src="PropertyOptionalComma/Error_MissingComma.js" type="text/traceur"></script>
<script src="PropertyOptionalComma/Error_TooManyCommas.js" type="text/traceur"></script>
<script src="PropertyOptionalComma/Error_TooManyCommas2.js" type="text/traceur"></script>
<script src="PropertyOptionalComma/Ok.js" type="text/traceur"></script>
<script src="Rest/Error_NotLast.js" type="text/traceur"></script>
<script src="Rest/Error_SetAccessor.js" type="text/traceur"></script>
<script src="Rest/Simple.js" type="text/traceur"></script>
<script src="QuasiLiterals/Default.js" type="text/traceur"></script>
<script src="QuasiLiterals/Error_Disabled.js" type="text/traceur"></script>
<script src="QuasiLiterals/Error_InvalidSubstitution.js" type="text/traceur"></script>
<script src="QuasiLiterals/Error_InvalidSubstitution2.js" type="text/traceur"></script>
<script src="QuasiLiterals/Error_NoWhitespaceAllowed.js" type="text/traceur"></script>
<script src="QuasiLiterals/Error_NotClosed.js" type="text/traceur"></script>
<script src="QuasiLiterals/Tag.js" type="text/traceur"></script>
<script src="Scope/Error_BlockBinding1.js" type="text/traceur"></script>
<script src="Scope/BlockBinding2.js" type="text/traceur"></script>
<script src="Scope/BlockBinding3.js" type="text/traceur"></script>
<script src="Scope/BlockBinding4.js" type="text/traceur"></script>
<script src="Scope/BlockBinding5.js" type="text/traceur"></script>
<script src="Scope/BlockBinding6.js" type="text/traceur"></script>
<script src="Scope/BlockBinding7.js" type="text/traceur"></script>
<script src="Scope/BlockBinding8.js" type="text/traceur"></script>
<script src="Scope/BlockBinding9.js" type="text/traceur"></script>
<script src="Scope/BlockBinding10.js" type="text/traceur"></script>
<script src="Scope/DeconstructingBlockBinding.js" type="text/traceur"></script>
<script src="Scope/DeepNestedLet.js" type="text/traceur"></script>
<script src="Scope/DeepNestedLetConst.js" type="text/traceur"></script>
<script src="Scope/DeepNestedLetVar.js" type="text/traceur"></script>
<script src="Scope/DeepNestedLetVarNoInit.js" type="text/traceur"></script>
<script src="Scope/Error_ConstMissingInitializer.js" type="text/traceur"></script>
<script src="Scope/Error_Disabled.js" type="text/traceur"></script>
<script src="Scope/Error_ForInWithInitializerConst.js" type="text/traceur"></script>
<script src="Scope/Error_ForInWithInitializerLet.js" type="text/traceur"></script>
<script src="Scope/Error_ForOfWithInitializerConst.js" type="text/traceur"></script>
<script src="Scope/Error_ForOfWithInitializerLet.js" type="text/traceur"></script>
<script src="Scope/Error_ForOfWithInitializerVar.js" type="text/traceur"></script>
<script src="Scope/Error_FunctionExpressionInBlock.js" type="text/traceur"></script>
<script src="Scope/ForInWithInitializerVar.js" type="text/traceur"></script>
<script src="Scope/Error_ForWithoutInitializerConst.js" type="text/traceur"></script>
<script src="Scope/LetForInInitializers1.js" type="text/traceur"></script>
<script src="Scope/LetForInitializers1.js" type="text/traceur"></script>
<script src="Scope/LetInClass.js" type="text/traceur"></script>
<script src="Scope/LetInClosure.js" type="text/traceur"></script>
<script src="Scope/LetInFor.js" type="text/traceur"></script>
<script src="Scope/LetInForBreak.js" type="text/traceur"></script>
<script src="Scope/LetInForBreakInner.js" type="text/traceur"></script>
<script src="Scope/LetInForBreakNamed.js" type="text/traceur"></script>
<script src="Scope/LetInForContinue.js" type="text/traceur"></script>
<script src="Scope/LetInForContinueInner.js" type="text/traceur"></script>
<script src="Scope/LetInForContinueNamed.js" type="text/traceur"></script>
<script src="Scope/LetInitializerFor1.js" type="text/traceur"></script>
<script src="Scope/LetInitializerFor2.js" type="text/traceur"></script>
<script src="Scope/LetInitializerFor3.js" type="text/traceur"></script>
<script src="Scope/LetInitializerForIn.js" type="text/traceur"></script>
<script src="Scope/LetInProperties.js" type="text/traceur"></script>
<script src="Scope/LetNoInitializer.js" type="text/traceur"></script>
<script src="Scope/LetNoInitializerGlobal.js" type="text/traceur"></script>
<script src="Scope/LetWithFor.js" type="text/traceur"></script>
<script src="Scope/LetWithForIn.js" type="text/traceur"></script>
<script src="Scope/LetWithSwitch.js" type="text/traceur"></script>
<script src="Scope/LetWithSwitch2.js" type="text/traceur"></script>
<script src="Scope/NestedFunction1.js" type="text/traceur"></script>
<script src="Scope/NestedFunction2.js" type="text/traceur"></script>
<script src="Scope/NestedFunction3.js" type="text/traceur"></script>
<script src="Scope/NestedLet.js" type="text/traceur"></script>
<script src="Scope/TopLevelLet.js" type="text/traceur"></script>
<script src="Scope/TopLevelLetConst.js" type="text/traceur"></script>
<script src="Scope/TopLevelLetVar.js" type="text/traceur"></script>
<script src="Spread/Array.js" type="text/traceur"></script>
<script src="Spread/Call.js" type="text/traceur"></script>
<script src="Spread/CallWithUndefined.js" type="text/traceur"></script>
<script src="Spread/Class.js" type="text/traceur"></script>
<script src="Spread/Error_Disabled.js" type="text/traceur"></script>
<script src="Spread/MethodCall.js" type="text/traceur"></script>
<script src="Spread/MethodCallQuotedName.js" type="text/traceur"></script>
<script src="Spread/New.js" type="text/traceur"></script>
<script src="Spread/New2.js" type="text/traceur"></script>
<script src="Spread/NewBuiltin.js" type="text/traceur"></script>
<script src="Spread/Type.js" type="text/traceur"></script>
<script src="StringExtras/Contains.js" type="text/traceur"></script>
<script src="StringExtras/EndsWith.js" type="text/traceur"></script>
<script src="StringExtras/StartsWith.js" type="text/traceur"></script>
<script src="StringExtras/ToArray.js" type="text/traceur"></script>
<script src="Yield/DoGenerator.js" type="text/traceur"></script>
<script src="Yield/EndYieldGenerator.js" type="text/traceur"></script>
<script src="Yield/Error_Disabled.js" type="text/traceur"></script>
<script src="Yield/Error_Disabled2.js" type="text/traceur"></script>
<script src="Yield/Error_MissingStar.js" type="text/traceur"></script>
<script src="Yield/Finally.js" type="text/traceur"></script>
<script src="Yield/ForOfGenerator.js" type="text/traceur"></script>
<script src="Yield/ForEmptyGenerator.js" type="text/traceur"></script>
<script src="Yield/ForGenerator.js" type="text/traceur"></script>
<script src="Yield/ForInGenerator.js" type="text/traceur"></script>
<script src="Yield/ForInGenerator2.js" type="text/traceur"></script>
<script src="Yield/ForInGenerator3.js" type="text/traceur"></script>
<script src="Yield/ForLexicallyNestedGenerator.js" type="text/traceur"></script>
<script src="Yield/IfGenerator.js" type="text/traceur"></script>
<script src="Yield/LabelledBreakGenerator.js" type="text/traceur"></script>
<script src="Yield/MapFilterGenerator.js" type="text/traceur"></script>
<script src="Yield/SequenceGenerator.js" type="text/traceur"></script>
<script src="Yield/SimpleGenerator.js" type="text/traceur"></script>
<script src="Yield/StatementTestGenerator.js" type="text/traceur"></script>
<script src="Yield/SwitchGenerator.js" type="text/traceur"></script>
<script src="Yield/Tree.js" type="text/traceur"></script>
<script src="Yield/TryCatchGenerator.js" type="text/traceur"></script>
<script src="Yield/TryCatchYieldGenerator.js" type="text/traceur"></script>
<script src="Yield/TryFinallyGenerator.js" type="text/traceur"></script>
<script src="Yield/WhileGenerator.js" type="text/traceur"></script>
<script src="Yield/tryFinallyFinallyGenerator.js" type="text/traceur"></script>
</head>
<body>
<script>

/**
 * Given a path like "feature/Foo/Bar" makes a function name to test that
 * feature: "testFooBar".
 */
function makeTestName(path) {
  var pathStart = 'feature/';
  var start = path.indexOf(pathStart) + pathStart.length;

  var name = path.substring(start);
  name = name.replace('/', '');
  name = name.replace('.js', '');

  return 'test' + name;
}

function assertNoOwnProperties(o) {
  var m = Object.getOwnPropertyNames(o);
  if (m.length) {
    fail('Unexpected members found:' + m.join(', '));
  }
}

function assertHasOwnProperty(o) {
  var args = Array.prototype.slice.call(arguments, 1);
  for (var i = 0; i < args.length; i ++) {
    var m = args[i];
    if (!o.hasOwnProperty(m)) {
      fail('Expected member ' + m + ' not found.');
    }
  }
}

function assertLacksOwnProperty(o) {
  var args = Array.prototype.slice.call(arguments, 1);
  for (var i = 0; i < args.length; i ++) {
    var m = args[i];
    if (o.hasOwnProperty(m)) {
      fail('Unxpected member ' + m + ' found.');
    }
  }
}

// Replace the Closure-provided array comparer with our own that doesn't barf
// because Array.prototype has a __iterator__ method.
function assertArrayEquals(expected, actual) {
  assertEquals(JSON.stringify(expected, null, 2),
               JSON.stringify(actual, null, 2));
}

function evalScript(scriptElement) {
  'use strict';

  var source;
  var name;
  var url = scriptElement.src || window.location.href;
  if (scriptElement.src) {
    name = scriptElement.src;
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, false);
    xhr.send();
    source = xhr.responseText;
  } else {
    name = 'inline-script';
    source = scriptElement.textContent;
  }

  // For each Traceur .js file, we'll create a top-level "test___" function
  // that compiles and evaluates it. JsUnit will then find and run those
  // functions for us.
  // We eval each file in the scope of its own function so we don't have to
  // worry about name clashes across the different feature scripts.
  var testName = makeTestName(name);
  window[testName] = function() {
    assertNotEquals('Failed to load file', '', source);

    var skip = false;
    var shouldCompile = true;
    var expectedErrors = [];

    forEachPrologLine(source, function(line) {
      var m;
      if (line.indexOf('// Should not compile.') === 0) {
        shouldCompile = false;
      } else if (line.indexOf('// Skip.') === 0) {
        skip = true;
      } else if ((m = /\/\ Options:\s*(.+)/.exec(line))) {
        traceur.options.fromString(m[1]);
    } else if ((m = /\/\/ Error:\s*(.+)/.exec(line))) {
      expectedErrors.push(m[1]);
    }
    });

    try {
      var reporter = new traceur.util.TestErrorReporter();
      var sourceFile = new traceur.syntax.SourceFile(name, source);
      var tree = traceur.codegeneration.Compiler.compileFile(reporter,
                                                             sourceFile,
                                                             url);
      var code = traceur.outputgeneration.TreeWriter.write(tree);

      if (!shouldCompile) {
        assertTrue('Expected error compiling ' + name + ', but got none.',
                   reporter.hadError());

        var missingExpectations = expectedErrors.forEach(function(expected) {
          assertTrue('Missing expected error: ' + expected,
                     reporter.hasMatchingError(expected));
        });

        skip = true;
      }

      if (!skip) {
          if (reporter.hadError()) {
            fail('Error compiling ' + name + '.');
            return;
          }

        // Script compiled, so run it.
        traceur.strictGlobalEval(code);
      }
    } finally {
      traceur.options.reset();
    }
  }
}

function forEachPrologLine(s, f) {
  var inProlog = true;
  for (var i = 0; inProlog && i < s.length; ) {
    var j = s.indexOf('\n', i);
    if (j == -1)
      break;
    if (s[i] === '/' && s[i + 1] === '/') {
      var line = s.slice(i, j);
      f(line);
      i = j + 1;
    } else {
      inProlog = false;
    }
  }
}

function evalAllScripts() {
  var scripts = document.querySelectorAll('script[type="text/traceur"]');
  Array.prototype.forEach.call(scripts, evalScript);
}

evalAllScripts();

</script>
</body>
</html>
